-- SdkAgent
-- Created by chengb Jun/19/2015
-- 负责sdk相关逻辑

update("game/sdk/SdkConst")

local PURE_FILE = "SdkAgent";

-- 内部函数声明

-- 是否是海外的安装包
function isOverseaPackage()
    if type(PUBLISH_PLATFORM) ~= "string" then
        -- 未配置运营平台
        return false;
    end

    -- 海外运营平台列表
    local overseaPlatforms = {
        PUBLISH_TYPE_GOOGLE_PLAY,
        PUBLISH_TYPE_APP_STORE,
        PUBLISH_TYPE_AMAZON,
    };
    return table.indexOf(overseaPlatforms, PUBLISH_PLATFORM) ~= -1;
end

-- 是否是青瓷平台的安装包
function isQCPackage()
    return PUBLISH_PLATFORM == PUBLISH_TYPE_QC;
end

-- 是否是Google APK的安装包
function isGoogleAPKPackage()
    if PUBLISH_PLATFORM == PUBLISH_TYPE_GOOGLE_PLAY and
       type(PAY_SDK) == "table" and #PAY_SDK > 0 then
       return true;
    end

    return false;
end

-- 获取第三方账号的存储字段
-- @param channel 渠道
function get3rdAccountPath(channel)
    return string.format("3rdplatform_info_%s", channel);
end

-- 设置第三方账号登录信息
function set3rdAccountLoginInfo(channel, info)
    local path = get3rdAccountPath(channel);
    _G[path] = info;
end

-- 清除第三方账号登录信息
function clear3rdAccountLoginInfo(channel)
    set3rdAccountLoginInfo(channel, nil);
end

-- 获取第三方账号登录信息
function get3rdAccountLoginInfo(channel)
    local path = get3rdAccountPath(channel);
    return _G[path];
end

-- 获取最近一次登录的第三方渠道
function getLastAccountChannel()
    return UserDefaultM.getStringForKey("LAST_ACCOUNT_CHANNEL");
end

-- 记录最近一次登录的第三方渠道
function setLastAccountChannel(channel)
    if type(channel) ~= "string" then
        return;
    end

    cclog("Record last 3rd account channel : " .. channel);
    UserDefaultM.setStringForKey("LAST_ACCOUNT_CHANNEL", channel);
end

-- 根据运营平台获取游客channel标识
function getGuestChannelName()
    -- 谷歌平台
    if PUBLISH_PLATFORM == PUBLISH_TYPE_GOOGLE_PLAY then
        return CHANNEL_GUEST_GP;
    -- 亚马逊平台
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_AMAZON then
        return CHANNEL_GUEST_AM;
    -- 苹果AppStore平台
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_APP_STORE or PUBLISH_PLATFORM == PUBLISH_TYPE_APP_STORE_CN then
        return CHANNEL_GUEST_AP;
    end
end

-- 判断是否游客channel
function isGuestChannel(channel)
    if channel == CHANNEL_GUEST_GP or
        channel == CHANNEL_GUEST_AM or
        channel == CHANNEL_GUEST_AP then
        return true;
    end

	-- 兼容以前的"guest"
	if channel == "guest" then
		return true;
	end

    return false;
end

-- 根据运营平台获取facebook的channel标识
function getFacebookChannelName()
    -- 谷歌平台
    if PUBLISH_PLATFORM == PUBLISH_TYPE_GOOGLE_PLAY then
        return CHANNEL_FACEBOOK_GP;
    -- 亚马逊平台
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_AMAZON then
        return CHANNEL_FACEBOOK_AM;
    -- 苹果appstore平台
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_APP_STORE or PUBLISH_TYPE_APP_STORE_CN then
        return CHANNEL_FACEBOOK_AP;
    end
end

-- 判断是否facebook的channel
function isFacebookChannel(channel)
    if channel == CHANNEL_FACEBOOK_GP or
        channel == CHANNEL_FACEBOOK_AM or
        channel == CHANNEL_FACEBOOK_AP then
        return true;
    end
    return false;
end

-- 显示Google账号登录窗口
function showGoogleLogin()
    if isAndroidPlatform() then
        local function callback()
            local path = get3rdAccountPath(CHANNEL_GOOGLE);
            _G[path] = nil;
            callJavaFunc("showGoogleLogin", {}, "()V");
        end

        EventMgr.fire(event.SHOW_PERMISSION_EXPLAIN, callback);
        return true;
    else
        alert(getLocStr("disable_function"));
    end
    return false;
end

-- 显示Facebook登录窗口
function showFacebookLogin()
    if isAndroidPlatform() then
        local path = get3rdAccountPath(getFacebookChannelName());
        _G[path] = nil;
        callJavaFunc("handleFacebookLogin", {}, "()V");
        return true;
    elseif isIphonePlatform() or isIpadPlatform() then
        FacebookAgent.loginFacebook();
        return true;
    else
        alert(getLocStr("disable_function"));
    end
    return false;
end

-- 显示GameCener登录窗口
function showGameCenterLogin()
    if isIphonePlatform() or isIpadPlatform() then
        GameCenterAgent.loginGameCenter();
        return true;
    else
        alert(getLocStr("disable_function"));
    end
    return false;
end

-- 判断是否登录了第三方平台账号
function hasLogin3rdPlatform(channel)
    -- 如果没有传入渠道，默认为最近一次使用的渠道
    channel = channel or getLastAccountChannel();

    local path = get3rdAccountPath(channel);
    local info = _G[path];
    if not info then
        return false;
    end

    if not info["account"] or not info["extra"] then
        return false;
    end

    return true;
end

-- 获取当前登录游戏的第三方平台账号名称
function getGaming3rdAccount()
    local gamingAccount = AccountM.getGamingAccount();
    if gamingAccount then
        -- 已经记录了游戏中的账号，直接返回
        return gamingAccount;
    end

    local channel = getLastAccountChannel();
    if not hasLogin3rdPlatform(channel) then
        -- 尚未登录第三方平台
        return nil;
    end

    local info = get3rdAccountLoginInfo(channel);

    -- 将第三方平台名称和账号拼接起来
    return string.format("%s_%s", info["extra"]["3rdplatform"], info["account"]);
end

-- 请求服务器认证第三方平台账号
function auth3rdPlatform(channel)
    channel = channel or getLastAccountChannel();
    if true ~= hasLogin3rdPlatform(channel) then
        trace(PURE_FILE, "尚未登录第三方平台(%s)账号，无法请求服务器认证。", channel);
        return false;
    end

    -- 记录最近一次登录的第三方账号渠道
    setLastAccountChannel(channel);

    local info     = get3rdAccountLoginInfo(channel);
    local userName = info["account"];
    local password = "";
    local extra    = info["extra"];
    local extraRaw = info["extra_raw"];

    printTable(info, "请求服务器认证第三方平台账号， info =");

    if EXPRESS_LOGIN and SERVER_IP and SERVER_PORT then
        trace(PURE_FILE, "开始登录游戏服务器，IP:%s, Port:%s", SERVER_IP, SERVER_PORT);
        Operation.cmd_login(userName, SERVER_IP, SERVER_PORT);
    else
        assert(type(CC_IP)          == 'string', "必须配置 CC_IP");
        assert(type(CC_PORT)        == 'string', "必须配置 CC_PORT");
        assert(type(SUPPORT_VERSION) == 'string', "必须配置 SUPPORT_VERSION");

        trace(PURE_FILE, "开始登录CC，IP:%s, Port:%s", CC_IP, CC_PORT);
        Operation.cmd_login_cc(userName, password, CC_IP, CC_PORT, SUPPORT_VERSION, extra, extraRaw);
    end

    return true;
end

---------------------
-- 通过sdk购买商品
-- @param sku 商品库存标识
function buyPurchaseBySdk(sku, pay_sdk, price)
    local agent;
    if isAndroidPlatform() then
        -- MyCard 支付
        if pay_sdk == "mycard" then
            agent = MyCardAgent;
        -- BluePay 支付
        elseif pay_sdk == "bluepay" then
            agent = BluePayAgent;
        -- MOL 支付
        elseif pay_sdk == "mol" then
            agent = MOLAgent;
        -- 支付宝支付
        elseif pay_sdk == "alipay" then
            agent = AlipayAgent;
        -- 微信支付
        elseif pay_sdk == "wechat" then
            agent = WechatAgent;
        -- GooglePlay平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_GOOGLE_PLAY then
            agent = GooglePlayAgent;
        -- 青瓷平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_QC then
            agent = AlipayAgent;
        -- UC平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_UC then
            agent = UCAgent;
        -- 亚马逊平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_AMAZON then
            agent = AmazonAgent;
        -- 小米平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_MI then
            agent = MIAgent;
        -- 雷霆平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_LT then
            agent = LeiTingAgent;
        end

    elseif isIphonePlatform() or isIpadPlatform() then
        -- AppStore平台
        if PUBLISH_PLATFORM == PUBLISH_TYPE_APP_STORE or PUBLISH_PLATFORM == PUBLISH_TYPE_APP_STORE_CN then
            agent = AppPurchaseAgent;
        -- 雷霆平台
        elseif PUBLISH_PLATFORM == PUBLISH_TYPE_LT then
            agent = LeiTingAgent;
        end
    end

    if agent then
        agent.buyPurchase(sku, price);
        return true;
    else
        alert(getLocStr("disable_function"));
        return false;
    end
end

-- 批量查询商品价格
function batchQuerySkuPrice(skuList)
    if type(skuList) ~= 'table' or #skuList == 0 then
        return;
    end

    -- 将所有sku拼接起来
    local skuStr = "";
    for i, sku in pairs(skuList) do
        skuStr = skuStr .. sku;
        if i < #skuList then
            skuStr = skuStr .. "|";
        end
    end

    local serverId = getCurrentServerId();
    local account =  getGaming3rdAccount() or "empty3rdAccount";
    if isAndroidPlatform() then
        local accountStr = serverId .. "|" .. account;
        callJavaFunc("batchQuerySkuPrice", {skuStr, accountStr}, "(Ljava/lang/String;Ljava/lang/String;)V");
    elseif isIosPlatform() then
        callOCFunc("batchQuerySkuPrice", { skuStr = skuStr, account = account, serverId = serverId, });
    end
end

-------------------------
-- 发送邮件
-- @param mail   收件人
-- @param title  标题
-- @param body   正文
function sendMailTo(mail, title, body)
    assert(type(mail)  == "string");
    assert(type(title) == "string");
    assert(type(body)  == "string");

    if isAndroidPlatform() then
        callJavaFunc("sendMailTo", { mail, title, body }, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
    else
        alert(getLocStr("disable_function"));
    end
end

-- 查询广告是否准备就绪
function queryAdReadyState()
end

-- 播放奖励广告
function playAwardAd()
end

-- 请求加载广告
function requestLoadAd()
end

-- 通知设置本地推送
function setLocalPush()
    -- 获取本地推送
    local pushInfo = PushM.getUserAllPush();

    for index, info in pairs(pushInfo) do
        local leftTime = info["leftTime"];
        local title = info["title"];
        local content = info["content"];

        if type(leftTime)  == "number" and type(title) == "string" and type(content)  == "string" then
            if isAndroidPlatform() then
                callJavaFunc("setPushEvent", { tostring(leftTime), title, content },
                    "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
            elseif isIphonePlatform() or isIpadPlatform() then
                local args = {
                    leftTime = tostring(leftTime),
                    title    = title,
                    content  = content,
                };
                callOCFuncWithClass("LocalPushWrap", "setPushEvent", args);
            end
        end
    end
end

-- 移除所有本地推送
function clearLocalPush()
    if isAndroidPlatform() then
        callJavaFunc("clearPushEvent", {}, "()V");
    elseif isIphonePlatform() or isIpadPlatform() then
        callOCFuncWithClass("LocalPushWrap", "clearPushEvent");
    end
end

-- 通知手机端玩家登录成功
function notifyMobileUserLogin(account, rid, name, serverId, serverTime, level, firstLoginTime)
    if isAndroidPlatform() then
        if PUBLISH_PLATFORM == PUBLISH_TYPE_UC then
            -- UC平台
            callJavaFuncWithClass("com.ChannelDelegate", "onUserLogin", {account, rid, name, tostring(serverId),
                tostring(level), tostring(firstLoginTime)},
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
        end

        -- 移除所有本地推送
        clearLocalPush();
    elseif isIphonePlatform() or isIpadPlatform() then
        callOCFuncWithClass("UserAccount", "onUserLogin", {
            account = account,
            rid = rid,
            name = name,
            serverId = tostring(serverId),
            level = level,
        });

        -- 移除所有本地推送
        clearLocalPush();
    end
end

-- 显示网页版的FAQ
function showWebFAQs()
    if isOverseaPackage() then
        -- 海外版本
        openUrl("http://qcplay.helpshift.com/a/slime-dungeon/");
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_LT then
        -- 雷霆平台
        openUrl("http://gumballs.leiting.com/jump.php");
    else
        -- 国内其他版本
        openUrl("http://gumball.helpshift.com/a/gumballs-dungeons/");
    end
end

-- 获取内置客服的会话标签
function getHelpShiftTags()
    if not AccountM then
        return UserDefaultM.getStringForKey("APP_LANG");
    end

    local channel = AccountM.getGamingAccountChannel();

    local tags = { getLang(), };
    if channel and channel ~= "" then
        table.insert(tags, channel);
    end

    local tagStr = "";
    for i, tag in pairs(tags) do
        if i < #tags then
            tagStr = tagStr .. tag .. "|";
        else
            tagStr = tagStr .. tag;
        end
    end

    return tagStr;
end

-- 是否开放Helpshift SDK
function isHelpshiftOpen()
    return HELPSHIFT_ENABLED == 1;
end

-- 显示内置客服FAQ
function showFAQs(brief)
    local metaData = brief or {};
    if ME and ME.user then
        -- 在游戏中
        local pet = ME.user:getActivePet();
        local regTime  = os.date("%c", ME.user.dbase:query("first_login_time") or 0);  -- 转成如下格式： 10/29/15 11:23:59
        local errorLog = string.sub(getErrorLog(), 1, 1024); -- 截取错误日志
        metaData = {
            ["account"]            = getGaming3rdAccount(),          -- 账号
            ["rid"]                = ME.user.dbase:query("rid"),     -- 玩家rid
            ["level"]              = ME.user:getLevel(),             -- 世界树等级
            ["reg_time"]           = regTime,                        -- 首次登录的时间
            ["gem"]                = ME.user:queryAttrib("gem"),     -- 当前钻石数量
            ["money"]              = ME.user:queryAttrib("money"),   -- 当前金币数量
            ["gem_spend"]          = GiftM.getProgress("gem") or 0,  -- 花费的钻石
            ["lang"]               = getLang(),                      -- 语言版本
            ["error_log"]          = errorLog,                       -- 报错日志
            ["pet_id"]             = pet.classId,                    -- 当前出战冈布奥
            ["total_recharge"]     = MarketM.calcTotalRecharge(),    -- 累积充值金额（美元）
            ["server_id"]          = getCurrentServerId(),           -- 区组ID
            ["pet_num"]            = PetM.getPetNum(),               -- 冈布奥数量
            ["last_recharge_time"] = MarketM.getLastRechargeTime();  -- 最近一次充值的时间
            ["last_recharge_id"]   = MarketM.getLastRechargeGoods(); -- 最近一次购买的充值商品
            ["charge_amount"]      = MarketM.getChargeAmount(),      -- 充值数
        };

        -- 如果当前在迷宫中，还需要传入如下信息
        if DungeonM.isInDungeon() then
            metaData["dungeon_id"] = DungeonM.getDungeonId();        -- 当前所在的迷宫ID
            metaData["layer"]      = DungeonM.currentLayer();        -- 当前所在的迷宫层数
        end
    end

    local tags     = getHelpShiftTags();
    local version  = tostring(CLIENT_VERSION);
    metaData["tags"]    = tags;          -- 会话标签
    metaData["version"] = version;       -- 客户端版本号

    trace("SdkAgent", "showFAQs:metaData = %o", metaData);

    if isHelpshiftOpen() then
        if isAndroidPlatform() then
            local jsonParams = json.encode(metaData);
            callJavaFuncWithClass("com.helpshift.HelpshiftDelegate", "showFAQs", { jsonParams }, "(Ljava/lang/String;)V");
        elseif isIosPlatform() then
            callOCFuncWithClass("HelpshiftWrap", "showFAQs", metaData);
        else
            showWebFAQs();
        end
    else
        -- 显示网页版FAQ
        showWebFAQs();
    end
end

-- 显示facebook分享对话框
function showFBShareDialog(title, desc, url, imageUrl, shareType)
    -- 如果与服务器的连接已断开，尝试重连
    if not Socket.isConnected() then
        LoginM.tryReconnect(getLocStr("warning_title"), getLocStr("disconnect_tip"));
        return;
    end

    assert(type(title)    == "string", "title必须为string类型");
    assert(type(desc)     == "string", "desc必须为string类型");
    assert(type(url)      == "string", "url必须为string类型");
    assert(type(imageUrl) == "string", "imageUrl必须为string类型");
    assert(type(shareType)== "number", "shareType必须为number类型");

    trace("SdkAgent", "title = %s", title);
    trace("SdkAgent", "desc = %s",  desc);
    trace("SdkAgent", "url = %s", url);
    trace("SdkAgent", "imageUrl = %s", imageUrl);

    if isAndroidPlatform() then
        callJavaFunc("showFBShareDialog", { title, desc, url, imageUrl, shareType, },
            "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
    elseif isIosPlatform() then
        callOCFuncWithClass("FacebookWrap", "shareFacebook", {
            title     = title,
            desc      = desc,
            url       = url,
            imageUrl  = imageUrl,
            shareType = shareType
        });
    else
        alert(getLocStr("disable_function"));
    end
end

-- 切换第三方账号
function switchThirdAccount()
    local ok = false;
    if PUBLISH_PLATFORM == PUBLISH_TYPE_UC then
        if UCAgent then
            UCAgent.switchUCAccount();
            ok = true;
        end
    elseif PUBLISH_PLATFORM == PUBLISH_TYPE_LT then
        if LeiTingAgent then
            LeiTingAgent.switchAccount();
            ok = true;
        end
    end

    if not ok then
        alert(getLocStr("disable_function"));
    end
end

-- 显示UC九游登录窗口
function showUCLogin()
    if isAndroidPlatform() then
        if UCAgent then
            local path = get3rdAccountPath(CHANNEL_UC);
            _G[path] = nil;
            UCAgent.showUCLogin();
            return true;
        else
            trace(PURE_FILE, "显示UC九游登录窗口失败：UCAgent尚未创建");
        end
    else
        alert(getLocStr("disable_function"));
    end

    return false;
end

-- 显示亚马逊登录窗口
function showAmazonLogin()
    if isAndroidPlatform() then
        if AmazonAgent then
            local path = get3rdAccountPath(CHANNLE_AMAZON);
            _G[path] = nil;
            AmazonAgent.showAmazonLogin();
            return true;
        else
            trace(PURE_FILE, "显示亚马逊登录窗口失败：AmazonAgent尚未创建");
        end
    else
        alert(getLocStr("disable_function"));
    end
    return false;
end

-- 显示小米登录窗口
function showMILogin()
    if isAndroidPlatform() then
        if MIAgent then
            local path = get3rdAccountPath(CHANNEL_MI);
            _G[path] = nil;
            MIAgent.showLogin();
            return true;
        else
            trace(PURE_FILE, "错误：MIAgent尚未创建");
        end
    else
        alert(getLocStr("disable_function"));
    end

    return false;
end

-- 显示雷霆登录
function showLTLogin()
    if isAndroidPlatform() then
        local path = get3rdAccountPath(CHANNEL_LT);
        _G[path] = nil;
        LeiTingAgent.login();
        return true;
    elseif isIosPlatform() then
        local path = get3rdAccountPath(CHANNEL_LT);
        _G[path] = nil;
        LeiTingAgent.showLogin();
    end

    return false;
end

-------------------------
-- 显示第三方账号登录窗口
-- @param channel 渠道
function show3rdAccountLogin(channel)
    local ret = false;
    if channel == CHANNEL_GOOGLE then
        -- Google+
        ret = showGoogleLogin();
    elseif isFacebookChannel(channel) then
        -- Facebook
        ret =showFacebookLogin();
    elseif channel == CHANNEL_AMAZON then
        -- 亚马逊
        ret = showAmazonLogin();
    elseif channel == CHANNEL_UC then
        -- UC
        ret = showUCLogin();
    elseif channel == CHANNEL_GAME_CENTER then
        -- Game Center
        ret = showGameCenterLogin();
    elseif channel == CHANNEL_MI then
        -- 小米
        ret = showMILogin();
    elseif channel == CHANNEL_LT then
        -- 雷霆
        ret = showLTLogin();
    else
        alert(getLocStr("disable_function"));
    end
    return ret;
end

-- 退出第三方账号登陆
function signOutWithChannel(channel)
    local path = get3rdAccountPath(channel);
    _G[path] = nil;

    if isAndroidPlatform() then
        if channel == CHANNEL_GOOGLE then
            callJavaFunc("handleGoogleLogout", {}, "()V");
        elseif isFacebookChannel(channel) then
            callJavaFunc("handleFacebookLogout", {}, "()V");
        elseif channel == CHANNEL_AMAZON then
            callJavaFunc("handleAmazonLogout", {}, "()V");
        else
            alert(getLocStr("disable_function"));
        end
    elseif isIosPlatform() then
        if channel == CHANNEL_GAME_CENTER then
            -- gamecenter不需要logout
        elseif isFacebookChannel(channel) then
            callOCFuncWithClass("FacebookWrap", "logoutFacebook");
        end
    end
end

-- 获取激活码链接
function getActivateCodeUrl(channel)
    if channel == CHANNEL_UC then
        return "http://www.9game.cn/slmbsydmg/";
    else
        return "";
    end
end

-- 获取设备信息
function getDeviceInfo()
    local deviceInfo = {};

    deviceInfo["device_id"]         = getDeviceId();
    deviceInfo["mac"]               = NetworkStatus.getMacAddress();
    deviceInfo["ip"]                = NetworkStatus.getIPAddress();
    deviceInfo["IMEI"]              = getIMEI();
    deviceInfo["app_version"]       = getBundleVersion();
    deviceInfo["os_version"]        = getOSVersion();
    deviceInfo["mobile_model"]      = getMobileModel();
    deviceInfo["net_mode"]          = NetworkStatus.getNetMode();
    deviceInfo["os_platform"]       = getPlatformName2();
    deviceInfo["country_code"]      = cc.Device:getCountryCode();
    deviceInfo["publish_platform"]  = PUBLISH_PLATFORM;

    if LeiTingAgent then
        -- 雷霆平台需要渠道编码
        deviceInfo["channel"] = LeiTingAgent.getChannelNo();
    end

    return deviceInfo;
end

-- 打开LOBL官方论坛
function openLobiOfficialCommunity()
    local webUrl = "https://web.lobi.co/special/community-lp/gumballs_dungeons";
    local schemeUrl = "lobi://game_community?gameId=gumballs_dungeons";
    if isAndroidPlatform() then
        callJavaFunc("openLobiOfficialCommunity", { webUrl, schemeUrl }, "(Ljava/lang/String;Ljava/lang/String;)V");
    elseif isIosPlatform() then
        local pasteboardStr = "{\"co.lobi.pasteboard.urlscheme\":\"lobi://game_community?gameId=gumballs_dungeons\"}";
        callOCFuncWithClass("LobiWrap", "openOfficialCommunity",
           { webUrl = webUrl,  schemeUrl = schemeUrl, pasteboardStr = pasteboardStr, });
    end
end

-- 分享功能是否开放
function isShareFuncOpen()
    if ServerStatusM.query("block_share") == 1 then
        -- 服务器屏蔽了分享功能
        return false;
    end

    if isOverseaPackage() then
        -- 海外版本
        return true;
    end

    -- 开放分享的国内平台
    local platforms = {
        PUBLISH_TYPE_LT,           -- 雷霆
        PUBLISH_TYPE_QC,           -- 青瓷平台（先驱服）
    };

    -- 只有微信和微博同时开放时，才判断为开放
    if table.indexOf(platforms, PUBLISH_PLATFORM) ~= -1 and
       WECHAT_ENABLED == 1 and WEIBO_ENABLED == 1  then
        return true;
    end

    return false;
end

-- 是否开放个人中心
function isAccountCenterOpen()
    if PUBLISH_PLATFORM == PUBLISH_TYPE_LT then
        return true;
    end
    return false;
end

-- 显示个人中心
function showAccountCenter()
    local ok = false;
    if PUBLISH_TYPE_LT then
        -- 雷霆平台
        if LeiTingAgent and LeiTingAgent.showAccountCenter then
            LeiTingAgent.showAccountCenter();
            ok = true;
        end
    end

    if not ok then
        alert(getLocStr("disable_function"));
    end
end
